<?php
/**
 * Created by 1971599474@qq.com
 * User: zhixuan
 * Date: 2019/12/15
 * Time: 15:21
 */

namespace app\admin\model;


use app\common\enum\BaseEnum;

class Role extends \app\common\model\Role
{

    public static function getAllRole(){
        $role = self::getAll()->each(function ($item){
            $item['status'] = BaseEnum::getBoolValue($item['status']);
        });
        return $role;
    }


    /*
     * 查询角色拥有的权限
     * @param int $role_id
     * @return array
     * */
    public static function getRolePrivilege($role_id){

        $privilegeIds = self::getFieldValue(['id'=>$role_id],'privilege_id');
        if(empty($privilegeIds)) return null;
        $privilege = Privilege::where('id','in',$privilegeIds)->select();
        if(empty($privilege)) return null;
        /*
        $map = [];
        foreach($privilege as $menu){
            if($menu->module_name == 'NULL') continue;
            $map[$menu->module_name.'/'.$menu->controller_name.'/'.$menu->action_name] = $menu->id;
        }
        */
        return $privilege;
    }
}